# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/pinetab2_defconfig
# Maintainer: Danct12 <danct12@disroot.org>
# Co-Maintainer: Stefan Hansson <newbyte@postmarketos.org>
pkgname=linux-pine64-pinetab2
pkgver=6.12.1
_danctnix_kernel_rel=1
pkgrel=0
pkgdesc="Pine64 PineTab 2 mainline"
arch="aarch64"
_carch="arm64"
_flavor="pine64-pinetab2"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native"
depends="kmod"
makedepends="
	bash
	bison
	findutils
	flex
	linux-headers
	postmarketos-installkernel
	openssl-dev
	perl
	xz
	zstd
"

# Source
_tags="v$pkgver-danctnix$_danctnix_kernel_rel"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_tags.tar.gz::https://github.com/dreemurrs-embedded/linux-pinetab2/archive/$_tags.tar.gz
	$_config
"
builddir="$srcdir/linux-pinetab2-${_tags:1}"
_outdir="out"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	install -Dm644 "$builddir/arch/$_carch/boot/Image" \
		"$pkgdir/boot/vmlinuz"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
919b7628d422b9022c366e57508b329ff63503a4f8579ca631d33cbf6a5bc0d608ba06eb3f2121824a9d237797548b8dd24dc32471e9b18dceaa2ace35b87f77  linux-pine64-pinetab2-v6.12.1-danctnix1.tar.gz
b77fcc6bf86d7aaa49f15e5eb848d8d0f50973b7f5ecf502a9f3bf0993ed177d4ed990b439dd93fe635d8cdb3c5e6a8c66a25eb4c1834a14bea03c4ac9678245  config-pine64-pinetab2.aarch64
"
